package com.acme.bankapp.service.network;

import java.io.*;

/**
 * Abstract class for bank network
 * @author alex
 */
public abstract class BankNetwork {
	protected BufferedReader reader;
	protected BufferedWriter writer;
	
	protected static final String SERVER_HOST = "127.0.0.1";
	protected static final int SERVER_PORT = 1234;
	protected static final int SERVER_BACKLOG = 10;
	
	protected static final String COMMAND_ADD_CLIENT = "add_client";
	protected static final String COMMAND_LIST_CLIENTS = "list_clients";
	protected static final String COMMAND_STOP = "stop";
	protected static final String COMMAND_EXIT = "exit";
	
	/**
	 * @param message the message
	 */
	public void sendMessage(String message) {
		try {
			writer.write(message);
			writer.newLine();
			writer.flush();
			System.out.println("Sent: " + message);
		} catch (IOException e) {
			System.out.println("Err: Sending message error!");
		}
	}
	
	/**
	 * @return the message
	 */
	public String recieveMessage() {
		String message = null;
		try {
			message = reader.readLine();
			System.out.println("Recieved: " + message);
		} catch (IOException e) {
			System.out.println("Err: Recieving message error!");
		}
		return message;
	}
}
